if(!jsx3.lang.Class.forName("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistSummary")) {
	jsx3.lang.Class.defineClass("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistSummary",
			ux.megatron.gui.WizardPanel,
			null,
			function (block) {
				/**
				 * instance initializer
				 * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
				 * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
				 */
				block.prototype.wizard=null;
				block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
					//call constructor for super class (the super expects the name of the object and the function that it is an instance of)
					this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
			};

				block.prototype.initialize = function(msg) {
					var me=this;
					this.wizard = this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgWizard");
					//load the CERT_TYPE
					//ux.cdb.admin.CommonCache.loadCache(['CERT_TYPE'], me,me.cacheLoaded);
					//get the cache
					var cache = ux.cdb.admin.CommonCache.getInstance();
					var box=this.getDescendantOfName("blkIdType").getDescendantOfName("selValue");
					box.setSourceXML(cache.getCache('CommonCache_CERT_TYPE'));
					this.getDescendantOfName("blkCooOrgLevel").getDescendantOfName("selValue").setSourceXML(cache.getCache('CommonCache_ORG_LEVEL'));
					this.getDescendantOfName("blkAreaCode").getDescendantOfName("selValue").setSourceXML(cache.getCache('CommonCache_REGION_CATEG'));
					this.getDescendantOfName("blkFirstBank").getDescendantOfName("selValue").setSourceXML(cache.getCache('CommonCache_AGENT_BANK'));
			
					if (!this.wizard.isEdit)
					{
					 	this.wizard.getDescendantOfName("buttonPrev").setEnabled(jsx3.gui.Form.STATEENABLED, true);
						delete this.buttonStatesArr;
	                    this.buttonStates="buttonPrev:ENABLED,buttonFinish:ENABLED";
						//got internal cooperation organization id&name
						ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "getInternalOrgObj", [], this, this.interCooperOrgLoaded);
						/*
						this.getDescendantOfName("lblRegionValue").getDescendantOfName("selValue1").setValue(ux.cdb.admin.Privilege.getProvinceCode());
						this.getDescendantOfName("lblRegionValue").onSelectChanged();
						*/
						this.getDescendantOfName("lblRegionValue").setDataByObject({logicalAreaCode: ux.cdb.admin.Privilege.getProvinceCode()});
						this.getDescendantOfName("blkSuperCode").getDescendantOfName("txtValue").setValue(ux.cdb.admin.Privilege.getProvinceCode(),true);
					}
					else
					{//current mode is edit
					 //get the data from server
					    this.getDescendantOfName("blkCooOrgBranch").getDescendantOfName("txtValue").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
						ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "getStudentAidCenter", [this.wizard.orgId], this, this.cooOrgBaseinfoLoaded);
					}

					me.repaint();
				}

				/**
				 *  call back function to get internal cooperation organization id&name
				 */
				block.prototype.interCooperOrgLoaded=function(backmessage)
				{
					console.log("\r\r\tgot the internal cooperation organization code"+ux.megatron.util.JSON.JSONtoString(backmessage)+"\r");
					this.wizard.internalOrgId=backmessage.content.data[0];
					this.getDescendantOfName("blkCooOrgBranch").getDescendantOfName("txtValue").setValue(backmessage.content.data[1]);	
					
					//reset the "Select" event of the selValue1 of the lblRegionValue
					this.getDescendantOfName("lblRegionValue").getDescendantOfName("selValue1").setEvent('this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistSummary").onProvinceSelected(this);',jsx3.gui.Interactive.SELECT);
				}
				
				
				/**
				 * function when province selected
				 */
				block.prototype.onProvinceSelected=function(obj)
				{
					//show the father cooperation organization code of this organization
					this.getDescendantOfName("blkSuperCode").getDescendantOfName("txtValue").setValue(obj.getValue(),true);
					//call the area onchange function
					obj.getAncestorOfType("ux.cdb.admin.dataautomate.AreaUpdater").onSelectChanged(obj);
						
				}
				
				block.prototype.cooOrgBaseinfoLoaded=function(backmsg)
				{
					var cache = ux.cdb.admin.CommonCache.getInstance();
					var i;
					backmsg.chnFullName=this.wizard.orgName;
					
					//because the UCC need the return object must had all the field that send from UCC, so save it,and merge with which user edit,and send back
					this.wizard.summaryObj=backmsg.content.data[0];
					this.wizard.internalOrgId=backmsg.content.data[0].branchCode;//save branchCode to Save
					//replace the cooperation organization code to name
					
					backmsg.content.data[0].cooperOrgTypeCode=ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@LoanAssist@OrgType");
					//replace the branch code to name
					var branchlist=cache.getCache('CommonCache_INTERNAL_ORG');
					var branch =branchlist.selectSingleNode("//record[@jsxid = '" + backmsg.content.data[0].branchCode + "']");
					backmsg.content.data[0].branchCode=branch.getAttribute("jsxtext");	

					var areaCode=backmsg.content.data[0].logicalAreaCode;
					
					//this.getDescendantOfName("blkLoanAssistInfo").setDataByObject(backmsg.content.data[0]);					

					var boxlist=this.getDescendantsOfType("ux.cdb.admin.dataautomate.GenericUpdater");
					for (i=0;i<boxlist.length;i++)
					{
						if (boxlist[i].getName() != "lblRegionValue") 
						{
							boxlist[i].applyData(backmsg.content.data[0]);
						}
					}
					//hidden others area list
					this.getDescendantOfName("blkCooOrgLevel").getDescendantOfName("selValue").setValue(backmsg.content.data[0].orgLevelCode);
					this.regionSelected(this.getDescendantOfName("blkCooOrgLevel").getDescendantOfName("selValue"));
					var level=this.getDescendantOfName("blkCooOrgLevel").getDescendantOfName("selValue").getText();

					//show the area
					
					this.applyAreaData(level,areaCode);
					//reset the "Select" event of the selValue1 of the lblRegionValue
					this.getDescendantOfName("lblRegionValue").getDescendantOfName("selValue1").setEvent('this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.CooOrgLoanAssistSummary").onProvinceSelected(this);',jsx3.gui.Interactive.SELECT);
				}

				//set the area date
				//set the area date
				block.prototype.applyAreaData=function(level,val)
				{

					var me = this;
					var docArea = ux.megatron.Main.getServer().getCache().getDocument('Area_doc');
					var sel3Record=null;// = docArea.getRecordNode(val);
					var sel2Record=null;// = sel3Record.getParent();
					var sel1Record=null;// = sel2Record.getParent();

					//console.log(docArea);
					try{
						
						if (level=="省") {
							sel1Record = docArea.getRecordNode(val);
							
							sel2Record=sel1Record.getFirstChild();
						}
						else if (level=="市")
						{
							
							sel2Record = docArea.getRecordNode(val);
					 		sel1Record = sel2Record.getParent();
							sel3Record=sel2Record.getFirstChild();
						}
						else
						{
							sel3Record = docArea.getRecordNode(val);
					 		sel2Record = sel3Record.getParent();
					 		sel1Record = sel2Record.getParent();
						}
						
					}catch(ex){
						throw 'You specified a error area code ,the code is not exists,code is:'+val;
					}
		
					//console.log('sels,from 1,2,3:',sel1Record,sel2Record,sel3Record);
					//Bull shit code,just for working....lost my face.
					var selDoc,children,child;
					var selects = this.getDescendantOfName("lblRegionValue").getDescendantsOfType('jsx3.gui.Select');
					for(var i=0;i<selects.length;i++){
						var sel = selects[i];
						var scriptEvent = sel.getEvent(jsx3.gui.Interactive.SELECT);
						var recordNode = eval('sel'+(i+1).toString()+'Record');
						
						if (recordNode==null)
						{
							continue;
						}
						if(i == 0){
							sel.setValue(recordNode.getAttribute('jsxid'));
						}else{
							selDoc = jsx3.xml.CDF.Document.newDocument();
							children = recordNode.getParent().getChildNodes();
					
							for(j=0;j<children.size();j++){
								child = children.get(j).cloneNode(false);
								selDoc.insertRecordNode(child);
							}
					
							sel.setSourceXML(selDoc);
							sel.setValue(recordNode.getAttribute('jsxid'),true);
						}
						sel.setEvent(scriptEvent,jsx3.gui.Interactive.SELECT);
					}
					//this.getDescendantOfName("lblRegionValue").onSelectChanged();
				}
		
				block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					//ready to save summary
					//get the general detail
					var dataField=this.getDescendantOfName("blkLoanAssistInfo");
					var msg=dataField.doValidate();
					if (msg!=null)
					{//Validate fail
						var tip = msg[0].label ? msg[0].label + ":" +msg[0].message : msg[0].message;
						this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").setWarnMessage(tip);
						return "NONE";
					}
					this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").clearWarnMessage();
					//give the sign that step one has already been visited
					
					return null; // return "NONE" to not next panels
				}
				//call back-- use for test
				block.prototype.backmessage=function(obj)
				{
				}

				block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					var content=this.wizard.getDescendantOfName("blkContent");
					var me=this;
					content.removeChildren();
					ux.megatron.Main.loadUIResourceAsync(content, "ux.cdb.admin", "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/builder/ui/CooOrgSelectType.xml", null);
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not last status
				}
				block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					//validate
					var dataField=this.getDescendantOfName("blkLoanAssistInfo");
					var msg=dataField.doValidate();

					if (msg!=null)
					{//Validate fail
						var tip = msg[0].label ? msg[0].label + ":" +msg[0].message : msg[0].message;
						this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").setWarnMessage(tip);
						return "NONE";
					}
					this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgLoanAssist.builder.Builder").clearWarnMessage();
				
					this.saveSummeryInfo();	
					return null; // return "NONE" to not last status
				}
				
				/**
				 *  save Summery Info
				 */
				block.prototype.saveSummeryInfo=function()
				{
					var dataField=this.wizard.getDescendantOfName("blkLoanAssistInfo");//get summary info from the UI
					var me = this;
					var summaryInfo=dataField.getDataAsObject();
					summaryInfo.cooperOrgTypeCode="2401"; //学生资助中心代码
					summaryInfo.branchCode= this.wizard.internalOrgId;
					summaryInfo.parentOrgId=this.getDescendantOfName("selValue1").getValue();//上级资助中心id
					this.partyId=summaryInfo.partyId;
					if (this.getDescendantOfName("selValue3").getDisplay()!=jsx3.gui.Block.DISPLAYNONE)
					{
						summaryInfo.logicalAreaCode=this.getDescendantOfName("selValue3").getValue();
					}
					else
					{
						if (this.getDescendantOfName("selValue2").getDisplay()!=jsx3.gui.Block.DISPLAYNONE)
						{
							summaryInfo.logicalAreaCode=this.getDescendantOfName("selValue2").getValue();
						}
						else
						{
							summaryInfo.logicalAreaCode=this.getDescendantOfName("selValue1").getValue();
						}
					}
					
					if (!this.wizard.isEdit) {
						//add mode save the info
						ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "saveStudentAidCenter", [summaryInfo], me, me.summaryInfoSaved);
					}
					else{
						//edit mode change the info
						//merge the edited message with the original message
						console.log("\r\r\t【original object of the cooperation organization summery】\r"+ux.megatron.util.JSON.JSONtoString(this.wizard.summaryObj)+"\t");
						for (field in summaryInfo)
						{
							this.wizard.summaryObj[field]=summaryInfo[field];
						}
						console.log("\r\r\t【After Edit object of the cooperation organization summery】\r"+ux.megatron.util.JSON.JSONtoString(this.wizard.summaryObj)+"\t");
						ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "updateStudentAidCenter", [this.wizard.summaryObj], me, me.summaryInfoSaved);
					}
				}

				/**
				 *  callback function when summary info saved 
				 */

				block.prototype.summaryInfoSaved = function(message)
				{
					if (!this.wizard.isEdit) 
					{
						this.partyId = message.content.data[0].partyId;
					}
					//summary info saved to save address info 
					this.saveAddressInfo(message);
					
				}

				/**
				 * function to save address info
				 */
				block.prototype.saveAddressInfo=function(message)
				{

					console.log("\r\r\t got the back message of the summary saved"+ux.megatron.util.JSON.JSONtoString(message));
					// to save address info		
					if (this.wizard.getDescendantOfName("blkRegAddress")) 
					{//user already visited the address info, to save address 
						var regAddress = this.wizard.getDescendantOfName("blkRegAddress").getDataAsObject();
						var officeAddress = this.wizard.getDescendantOfName("blkOfficeAddress").getDataAsObject();
						var data;
						var me = this;
						regAddress.partyId = this.partyId;
						regAddress.addrId = this.wizard.regAddrId;
						regAddress.addrTypeCode = "02";
						regAddress.postalCode = null;
						regAddress.website = null;
						regAddress.emailAddr = null;
						regAddress.phoneNbr = null;
						regAddress.faxNbr = null;
						
						officeAddress.partyId = this.partyId;
						officeAddress.addrId = this.wizard.offAddrId;
						officeAddress.addrTypeCode = "03";
												
						data=[regAddress,officeAddress];
						/* @JSC :: begin DEBUG */
						console.log("\r\r\t ready to save the address info \r"+ux.megatron.util.JSON.JSONtoString(data));
						/* @JSC :: end */
						if (this.wizard.isEdit) 
						{	
							//current mode is edit existed address
							ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "updateBatchAddress", [data], me, me.addressSaved);
						}
						else 
						{
							
							//current mode is add new address
							ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "saveBatchAddress", [data], me, me.addressSaved);
							
						}
					}
					else
					{//user never visit address into,jump to save linkman info
						this.addressSaved(message);
					}
				}	
				
				//address info saved,received the back message from server
				block.prototype.addressSaved=function(message)
				{
		
					/* @JSC :: begin DEBUG */
					console.log("\r\r\t got the address info saved message"+ux.megatron.util.JSON.JSONtoString(message)+" \r");
					/* @JSC :: end */
					//address info saved,save likeman info
					if (this.wizard.getDescendantOfName("mtxEditLinkman")==null) 
					{//if user not fill linkman info
						this.linkmanSaved(message);
						return;
					
					}
					var record=this.wizard.getDescendantOfName("mtxEditLinkman").getXML().getChildNodes();
		
					var data=new Array();
					var me=this;
					for(var i=0;i<record.size();i++)
					{
						if (record.get(i).getAttribute("jsxIsModify") == "true") {
							if (record.get(i).getAttribute("jsxIsNew") == "true") {
								data.push({
									partyId:this.partyId,
									contactPersonId:null,
									contactPersonTypeCode: record.get(i).getAttribute("jsxtype"),//联系人类型
									contactPersonName: record.get(i).getAttribute("jsxname"),//联系人姓名
									contactPersonFixPhone: record.get(i).getAttribute("jsxtelephone"),//固定电话
									contactPersonMobNum: record.get(i).getAttribute("jsxcellphone"),//移动电话
									contactPersonEmail: record.get(i).getAttribute("jsxemail"), //电子邮件	
									ContactFaxNbr:"" //传真	
								});
							}
							else
							{
								data.push({
									partyId:this.partyId,
									contactPersonId: record.get(i).getAttribute("jsxid"),//联系人ID
									contactPersonTypeCode: record.get(i).getAttribute("jsxtype"),//联系人类型
									contactPersonName: record.get(i).getAttribute("jsxname"),//联系人姓名
									contactPersonFixPhone: record.get(i).getAttribute("jsxtelephone"),//固定电话
									contactPersonMobNum: record.get(i).getAttribute("jsxcellphone"),//移动电话
									contactPersonEmail: record.get(i).getAttribute("jsxemail"), //电子邮件
									ContactFaxNbr:"" //传真	
								});
							}
						}
						
					}
					console.log("\n\n\t send linkman message to save "+ux.megatron.util.JSON.JSONtoString(data));
					if (data.length > 0) {
						if (this.wizard.isEdit) {
							//current mode is edit  call upate
							ux.megatron.util.Dwr.callDwr("MaintainCooperOrgUCC", "updateContactPersonList", [data], me, me.linkmanSaved);
						}
						else{
							//current mode is add call save
							ux.megatron.util.Dwr.callDwr("AddCooperOrgUCC", "saveContactPerson", [data], me, me.linkmanSaved);
						}
					}
					else
					{//no likeman info need to save,save the baseinfo
						this.linkmanSaved(message);
					}
				}
				//receive the back message about save likeman info
				block.prototype.linkmanSaved = function(message) {
					/* @JSC :: begin DEBUG */
					console.log("\r\r\t all info saved message:"+ux.megatron.util.JSON.JSONtoString(message)+" \r");
					/* @JSC :: end */
					//all saved
					if (this.wizard.isEdit) 
					{
						
						if (message.res.flag == 1) 
						{
							alert(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@ModifyCooOrgNotice"));
						}
						ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.cooOrg.CooOrg")[0].onRefresh(this.wizard.isEdit);
					}
					else
					{
						//ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.cooOrg.CooOrg")[0].getDescendantOfName("blkSearchName").getDescendantOfName("txtValue").setValue(this.wizard.orgName);
						//ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.cooOrg.CooOrg")[0].onSearch();
						if (message.res.flag == 1) 
						{
							alert(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@AddCooOrgNotice"));
						}
					}
					this.wizard.doClose();
					this.wizard.opener.onRefresh();
				}
				


				block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					this.getAncestorOfType("ux.cdb.admin.mechanism.cooOrg.CooOrgWizard").onClose();
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
					if(!this.getChild(0)) {
						var me = this;
						ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/builder/step1/ui/CooOrgLoanAssistSummaryContent.xml", me, me.initialize);
					}
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
					return null; // return "NONE" to not advance panels
				}
				
				/**
				 *  when user change user's id type,modify the validate method
				 */
				block.prototype.onIDTypeChange=function(idType)
				{
					var valType;
					if (idType==="01" || idType==="02")
					{
						valType="IDCard";
					}
					else
					{
						valType="";						
						
					}
					this.getDescendantOfName("blkIDCode").setValidator(valType);
				}
				
				block.prototype.regionSelected=function(obj)
				{
					var selValue2=this.getDescendantOfName("selValue2");
					var selValue3=this.getDescendantOfName("selValue3");
					if (obj.getValue()=="01") {
						selValue2.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
						selValue3.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
		
						return;
					}
					else if (obj.getValue()=="02")
					{
						selValue2.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						selValue3.setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
		
						return;	
					}
					else
					{
						selValue2.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						selValue3.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
						return;
			
					}
					
				}
			}
	);
}
